<?php

require_once dirname(__FILE__).'/../lib/close_leavesGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/close_leavesGeneratorHelper.class.php';

/**
 * close_leaves actions.
 *
 * @package    Amawal Invest
 * @subpackage close_leaves
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class close_leavesActions extends autoClose_leavesActions
//class close_leavesActions extends sfActions
{

    public function executeBatchNotify(sfWebRequest $request){
        $ids = $request->getParameter('ids');
        if(!$ids || !is_array($ids) || count($ids) == 0 ){
            $this->getUser()->setFlash('error','No transactions selected');
        }
        $c= new Criteria();
        $c->add(TransactionPeer::NOTIFICATION_FLAG , 0 );
        $c->add(TransactionPeer::ID , $ids , Criteria::IN );

        $trs = TransactionPeer::doSelectJoinAllExceptBranch($c);

        /*@var $tra Transaction*/
        $ret = false;
        if(count($trs) > 0 ){

            $message = get_partial('global/mails/no_closing_notification',array('trs'=>$trs));

            $message = $this->getMailer()->compose (
            array(globals::DEMO_BRANCH_OWNER_EMAIL => globals::DEMO_BRANCH_OWNER_NAME)
            , globals::DEMO_BRANCH_OWNER_EMAIL
            , __('No closing T.A transacionts')
            , $message
            );
            $message->setContentType("text/html");
            $ret = $this->getMailer()->send($message);
        }

        if($ret){
            foreach ($trs as $tra){
                $tra->setNotificationFlag(1);
                $tra->save();
            }
            $this->getUser()->setFlash('notice','The Notification proccess is completed successfully !');
        }else{
            $this->getUser()->setFlash('error','Transactions that are selected are all notified before');
        }


        //if($ret)






    }
}
